package com.team2.outpatient_sys.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebMvcConfig implements WebMvcConfigurer {
    //当前跨域请求最大有效时长,1天
    private static final long MAX_AGE = 24 * 60 * 60;

    //解决跨域问题
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")  //设置映射
                .allowedOriginPatterns("*")     //设置访问源地址
                .allowedHeaders("*")            //允许的请求头
                .allowedMethods("GET", "POST", "PUT", "DELETE", "HEAD", "OPTIONS")      //设置允许请求的方法
                .allowCredentials(true)         //是否允许携带cookie
                .maxAge(MAX_AGE);               //设置最长有效期

    }
}
